package net.example.lesson2.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Aspect
public class LogOperationAspect {

    /**
     * 日志服务.
     */
    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 构造函数.
     */
    public LogOperationAspect() {
    }

    /**
     * 切入点声明.
     *
     * @param logOperation 注解参数提取action Name
     */
    @Pointcut("@annotation(logOperation)")
    public void handlePointCut(final LogOperation logOperation) {
    }

    /**
     * 环绕增强.
     */
    @Around("handlePointCut(logOperation)")
    public Object handleAround(final ProceedingJoinPoint joinPoint, final LogOperation logOperation) throws Throwable {
        logger.info("操作前日志记录...");
        final Object proceed = joinPoint.proceed();
        logger.info("操作后日志记录...");
        return proceed;
    }
}
